#pragma once
#include "EXListCtrl.h"
#include "EXScrollBar.h"
#include "EXListCtrlWndResSet.h"
// CEXListCtrlWnd

class AFX_EXT_CLASS CEXListCtrlWnd : public CWnd
{
	friend class CEXScrollBar;

	DECLARE_DYNAMIC(CEXListCtrlWnd)

public:
	CEXListCtrlWnd();
	virtual ~CEXListCtrlWnd();

	BOOL Create(const RECT& rect, CWnd* pParentWnd, UINT nID = -1);
	BOOL CreateCtrls();

	void SetListCtrl(CListCtrl * pList, COLORREF crBkgnd);
	void SetScrollWidth(UINT nScrollWidth = 20);
	void SetHScrollHeight(UINT nScrollHeight);
	void SetVScrollWidth(UINT nScrollWidth);
	void SetLayout(int nWidth, int nHeight);

	int InsertColumn(int nCol, const LVCOLUMN* pColumn);
	int InsertColumn(int nCol, LPCTSTR lpszColumnHeading,int nFormat=LVCFMT_LEFT, 
                  int nWidth = -1, int nSubItem = -1);

	int InsertItem(const LVITEM* pItem);
	int InsertItem(int nItem, LPCTSTR lpszItem);
	int InsertItem(int nItem, LPCTSTR lpszItem, int nImage);

	BOOL SetItemText(int nItem, int nSubItem, LPCTSTR lpszText);
	
	void SetHScrollLeftArrow(UINT nID, int nPic);
	void SetHScrollRightArrow(UINT nID, int nPic);
	void SetHScrollPage(UINT nID, int nPic);
	void SetHScrollThumb(UINT nID, UINT nBkgndID, UINT nIconID, int nPic,
		                  int nLeftWidth = 0, int nRightWidth = 0, 
                      int nTopHeight = 0, int nBottomHeight = 0);

	void SetVScrollLeftArrow(UINT nID, int nPic);
	void SetVScrollRightArrow(UINT nID, int nPic);
	void SetVScrollPage(UINT nID, int nPic);
	void SetVScrollThumb(UINT nID, UINT nBkgndID, UINT nIconID, int nPic,
		                  int nLeftWidth = 0, int nRightWidth = 0, 
                      int nTopHeight = 0, int nBottomHeight = 0);

	void SetExtra(UINT nID);

	void SubClassHeaderCtrl();
	void SetHeaderBitmap(UINT nID);
	void SetHeaderColor(COLORREF crHeader);

	BOOL SetItemState(int nItem, LVITEM* pItem);
	BOOL SetItemState(int nItem, UINT nState, UINT nMask);

	DWORD SetExtendedStyle(DWORD dwNewStyle);
	DWORD GetExtendedStyle();

	BOOL DeleteAllItems();
	BOOL DeleteItem(int nItem);

	POSITION GetFirstSelectedItemPosition() const;
	int GetNextSelectedItem(POSITION& pos) const;

	UINT GetSelectedCount() const;

	int GetItemCount() const;
	DWORD_PTR GetItemData(int nItem) const;
	BOOL SetItemData(int nItem, DWORD_PTR dwData);

	void SetListCtrlName(CString strName);

	CListCtrl * operator & ();
	CEXListCtrlWnd * GetAddress();

	CString GetItemText(int nItem, int nSubItem) const;
	int GetItemText(__in int nItem, __in int nSubItem, 
                  __out_ecount_part_z(nLen, return + 1) LPTSTR lpszText, 
                  __in int nLen) const;
      
	BOOL EnsureVisible(int nItem, BOOL bPartialOK);

	void Sort();

	void SetListColor(COLORREF crEven, COLORREF crOdd);
	void SetTextColor(COLORREF crText);

	void SetFont(CFont* pFont, BOOL bRedraw = TRUE);

	void LockHeader() { m_ListCtrl.LockHeader(); }
	void UnlockHeader() { m_ListCtrl.UnlockHeader(); }

	void GetSortColumn(CString & strColumn, BOOL & bAscend);

	int GetColumnWidth(int nCol) const;
	BOOL SetColumnWidth(int nCol, int cx);

	int GetHotItem();
	int SetHotItem(int iIndex);

	BOOL SelectItem(int nIndex, BOOL bSelect = TRUE);

	void SetItemCount(int nItems);

  void SetResSet(CEXBaseResSet* pResSet);
  CEXListCtrlWndResSet* m_pListWndResSet;

protected:
	void Sort(int nColumn, BOOL bAscend);
	void HScrollShow(BOOL bShow);
	void VScrollShow(BOOL bShow);

	int m_nScrollW;
	int m_nScrollH;
	int m_nHScrollHeight;
	int m_nVScrollWidth;

	CEXListCtrl m_ListCtrl;
	CEXScrollBar m_VScroll;
	CEXScrollBar m_HScroll;

	DWORD m_dwListStyle;
	DWORD m_dwListExStyle;

	UINT m_uExtraBitmapID;
	CBitmap m_bmpExtra;

protected:
	DECLARE_MESSAGE_MAP()
public:
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void OnPaint();
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
	afx_msg LRESULT OnDefListEraseNotify(WPARAM w, LPARAM l);
	afx_msg LRESULT OnCustomsizeHeader(WPARAM, LPARAM);

};


